package com.rw.coco.test.dataapi;

import com.rw.coco.api.data.CacheMapper;
import com.rw.tool.util.cache.CacheHashMap;

import java.util.Optional;

public class MemoryCacheMapper implements CacheMapper {
    private static final CacheHashMap<String, String> cacheHashMap = new CacheHashMap<>();

    @Override
    public void save(String key, String data, long millisecond) {
        cacheHashMap.put(key, data, millisecond);
    }

    @Override
    public void replace(String key, String data) {
        cacheHashMap.replace(key, data);
    }

    @Override
    public Optional<String> get(String key) {
        return Optional.ofNullable(cacheHashMap.get(key));
    }

    @Override
    public void delete(String key) {
        cacheHashMap.remove(key);
    }
}
